package com.zhm.demo.utils.time;

import java.time.LocalTime;

public class TimeInterval {
    private LocalTime start;
    private LocalTime end;

    public TimeInterval(LocalTime start, LocalTime end) {
        if (start.isAfter(end)) {
            throw new IllegalArgumentException("Start time must be before end time");
        }
        this.start = start;
        this.end = end;
    }

    public LocalTime getStart() {
        return start;
    }

    public LocalTime getEnd() {
        return end;
    }

    // 判断两个时间段是否重叠
    public boolean overlaps(TimeInterval other) {
        if (this.end.isBefore(other.start) || this.start.isAfter(other.end)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return start.toString() + " - " + end.toString();
    }
}